package com.crm.customer.controller;

import com.crm.common.pojo.Activity;
import com.crm.customer.service.ActivityService;
import com.crm.global.exception.ExceptionEnum;
import com.crm.global.result.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "交往记录管理")
@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @ApiOperation("查询所有交往记录")
    @GetMapping("/findAll")
    @ApiImplicitParam(name = "customerId",value = "客户id",paramType = "query",required = true)
    public ResponseEntity<Message<List<Activity>>> findAll(Long customerId) {
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS,activityService.findAll(customerId)));
    }

    @ApiOperation("保存交往记录")
    @PostMapping("/save")
    public ResponseEntity<Message<String>> save(@RequestBody  Activity activity) {
        activityService.saveOrUpdate(activity);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }

    @ApiOperation("更新交往记录")
    @PostMapping("/update")
    public ResponseEntity<Message<String>> update(@RequestBody Activity activity) {
        activityService.saveOrUpdate(activity);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }

    @ApiOperation("删除交往记录")
    @GetMapping("/delete")
    @ApiImplicitParam(name = "id",value="交往记录id",paramType = "query",required = true)
    public ResponseEntity<Message<String>> delete(Long id) {
        activityService.deleteById(id);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }

}
